package com.mall.user.domain.event;

import com.mall.user.domain.model.User;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;

/**
 * 用户创建领域事件
 * 当用户成功创建时发布此事件
 */
@Getter
public class UserCreatedEvent extends ApplicationEvent {
    
    private final User user;
    private final long eventTimestamp;
    
    public UserCreatedEvent(Object source, User user) {
        super(source);
        this.user = user;
        this.eventTimestamp = System.currentTimeMillis();
    }
    
    /**
     * 获取用户ID
     */
    public Long getUserId() {
        return user.getId();
    }
    
    /**
     * 获取用户名
     */
    public String getUserName() {
        return user.getName().name();
    }
    
    /**
     * 获取用户邮箱
     */
    public String getUserEmail() {
        return user.getEmail().email();
    }
    
    @Override
    public String toString() {
        return String.format("UserCreatedEvent{userId=%d, userName='%s', email='%s', eventTimestamp=%d}", 
                getUserId(), getUserName(), getUserEmail(), eventTimestamp);
    }
}